package aries.database;

/******************************************************************************
 * You may modify, publish, and use Aries for your own purpose. BUT
 * DON'T REMOVE THIS TEXT.
 * Visit my facebook: http://www.facebook.com/freeskies or
 * Follow my twitter: @freeskys
 *
 *
 * Author: Harditya Rahmat Ramadhan
 * Licence: GPLv2
 *****************************************************************************/

import aries.Configuration;
import java.io.File;
import java.util.ArrayList;

public class DatabaseConfiguration extends Configuration {

    /**
     * Name of the configuration file.
     */
    private String filename = "conf.ini";
    
    /**
     * Title type.
     */
    public static final byte TITLE = 0;
    
    /**
     * Value type.
     */
    public static final byte VALUE = 1;
    
    /**
     * Get default value for configuration file.
     * 
     * @param type
     * @return ArrayList
     */
    public static ArrayList<String> get(byte type) {
        ArrayList<String> result = new ArrayList<String>();
        if (type == TITLE) {
            result.add("ip");
            result.add("port");
            result.add("dbName");
            result.add("user");
            result.add("password");
            result.add("product");
        } else if (type == VALUE) {
            result.add(Database.getIp());
            result.add(Database.getPort());
            result.add(Database.getDbName());
            result.add(Database.getUser());
            result.add(Database.getPass());
            result.add(String.valueOf(Database.getProduct()));
        }
        return result;
    }
    
    /**
     * Create new saved database configuration.
     * The name of your configuration file is <code>conf.ini</code>
     */
    public DatabaseConfiguration(ArrayList<String> title, ArrayList<String> value) {
        super(title, value);
    }
    
    /**
     * Create new saved database configuration.
     * 
     * @param filename 
     */
    public DatabaseConfiguration(String filename, ArrayList<String> title, ArrayList<String> value) {
        super(filename, title, value);
    }
    
    /**
     * Create new saved database configuration.
     * 
     * @param filename 
     */
    public DatabaseConfiguration(File filename, ArrayList<String> title, ArrayList<String> value) {
        super(filename, title, value);
    }
    
    /**
     * Generate database configuration into a file.
     * 
     * @throws Exception 
     
    public void generate() throws Exception {
        Ini ini = new Ini(filename);
        String[] title = {"ip", "port", "dbName", "user", "password", "product"};
        String user = getUser();
        String pass = getPass();
        if (Setting.getUseEncrypt()) {
            //@Todo: change with other enryption
        	user = new AES(getUser()).encrypt(Setting.key);
        	pass = new AES(getPass()).encrypt(Setting.key);
        }
        String[] value = {getIp(), getPort(), getDbName(), user, pass, String.valueOf(getProduct())};
        ini.create(title, value, "Aries database configuration file.");
    }*/
    
}